﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model;

public partial class Auditors_Default : BasePage
{
    private List<CreateBankEntity> list;
    private string str = "Bank";
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            list = new List<CreateBankEntity>();
            Session[str] = list;

            dropExplain.Items.Add(new ListItem("1:入", "1"));
            dropExplain.Items.Add(new ListItem("1:出", "2"));
            dropExplain.Items.Add(new ListItem("3:利息", "3"));
            dropExplain.Items.Add(new ListItem("4:管理费", "4"));


            dropCurrency.Items.Add(new ListItem("4:管理费", "4"));
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        list = Session[str] as List<CreateBankEntity>;
        if(list==null)
        {
            list = new List<CreateBankEntity>();
        }
        string company = Request.QueryString["CompanyID"];
        CreateBankEntity entity = new CreateBankEntity();
        entity.Amount = txtAmount.Text;
        entity.CompanyID = company;
        entity.Currency = dropCurrency.SelectedValue;
        entity.Date = txtDate.Text;
        entity.Explain = dropExplain.SelectedValue;
        entity.VoucherNo = txtVoucherNo.Text;

        string msg = "";
        if (new AuditorsBLL().CreateCompanyBank(entity, out msg))
        {
            //Response.Redirect("SelectBank.aspx?CompanyID=" + company);
            
            Clearn();
        }
        else
        {
            if (msg.ToLower().StartsWith("sql自定义异常:"))
            {
                AlertMsg(msg.ToLower().Replace("sql自定义异常:", ""));
            }
            else
            {
                AlertMsg("插入失败，请检查数据是否异常");
            }
        }

    }

    void Clearn()
    {
        txtVoucherNo.Text = "";
        txtDate.Text = "";
        txtAmount.Text = "";
        dropExplain.Items[0].Selected = true;
        txtVoucherNo.Focus();
    }
}